package com.ruoyi.xiche.mapper;

import com.ruoyi.xiche.domain.PackagePriceDTO;
import com.ruoyi.xiche.domain.ServicePackage;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
* @author wangruoyang
* @description 针对表【service_package(服务套餐表)】的数据库操作Mapper
* @createDate 2025-03-20 14:25:55
* @Entity com.ruoyi.xiche.domain.ServicePackage
*/
@Mapper
public interface ServicePackageMapper extends BaseMapper<ServicePackage> {

    @Select("SELECT " +
            "  p.package_name AS packageName, " +
            "  SUM(i.original_price) AS originalTotalPrice, " +
            "  p.discount AS discount, " +
            "  SUM(i.original_price) * p.discount AS discountedPrice " +
            "FROM service_package p " +
            "LEFT JOIN service_package_item pi ON p.package_id = pi.package_id " +
            "LEFT JOIN service_item i ON pi.service_id = i.service_id " +
            "WHERE p.store_id = #{storeId} " +
            "GROUP BY p.package_id")
    List<PackagePriceDTO> selectPackagePrices(@Param("storeId") Long storeId);
}




